package me.xue.communityhealth.service;

import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.DrugPlace;
import me.xue.communityhealth.repo.DrugPlaceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugPlaceService implements BaseService<DrugPlace, Integer> {

    private final DrugPlaceRepository drugPlaceRepository;

    @Autowired
    public DrugPlaceService(DrugPlaceRepository drugPlaceRepository) {
        this.drugPlaceRepository = drugPlaceRepository;
    }

    @Override
    public int save(DrugPlace drugPlace) {
        return drugPlaceRepository.save(drugPlace);
    }

    @Override
    public int update(DrugPlace drugPlace) {
        return drugPlaceRepository.update(drugPlace);
    }

    @Override
    public int delete(Integer which) {
        return drugPlaceRepository.delete(which);
    }

    public DrugPlace findOne(Integer which) {
        DrugPlace drugPlace = drugPlaceRepository.findOne(which);
        if (drugPlace == null) {
            throw new ObjectNotFoundException();
        }
        return drugPlace;
    }

    @Override
    public List<DrugPlace> findAll() {
        return drugPlaceRepository.findAll();
    }
}
